import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Login from '@/components/Login.vue'
import Welcome from '@/components/Welcome'
import Users from '@/components/Users'
import Music from '@/components/Music'
import Shopping from '@/components/Shopping'
import Article from '@/components/Article'
import Addarticle from '@/components/Addarticle'
import Toarticle from '@/components/Toarticle'
import Editarticle from '@/components/Editarticle'
import Mycar from '@/components/Mycar'
import Musichome from '@/components/Musichome'
import Musiclist from '@/components/Musiclist'
import Musicfooter from '@/components/Musicfooter'
import Musicdetail from '@/components/Musicdetail'
Vue.use(Router)

const router= new Router({
  mode: 'history', 
  routes: [
   
    { 
      path: '/',
      component: HelloWorld,
      redirect:'/welcome',
      children:[{
        path:'/welcome',
        component:Welcome
      },{
        path:'/users',
        component:Users
      },
      {
        path:'/article/',
        component:Article,
       
      },
      {
        path:'/shopping',
        component:Shopping
      },
      {
        path:'/music',
        component:Music
      },

     {
       path:'/musicfooter',
        component:Musicfooter,
        redirect:'/musichome',
        children:[
          {
            path:'/musichome',
            component:Musichome,
          },
          {
           path:'/musiclist/:id',
        component:Musiclist,
       
        },
        {
          path:'/musicdetail/:id',
          component:Musicdetail
         } 
      
      ]
    },
      
      
      
     
    ]
    },
    {
      path:'/login',
      component:Login
    },
    {
      path:'/addarticle',
      component:Addarticle
    },
    {
      path:'/toarticle/:id',
      component:Toarticle,
      name:'toarticle'
    },
    {
      path:'/editarticle/:editid',
      component:Editarticle,
      name:'editarticle'
    },
    {
      path:'/mycar',
      component:Mycar
    },
  
  ]

})
export default router

router.beforeEach((to,from,next)=>{
  if(to.path=='/login') return next();
  const tokeni=window.sessionStorage.getItem('token');
  if(!tokeni) return next('/login');
  next();
})
